﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AdvancedCollectionsPerformanceTests
{
    public abstract class TreeBasePerformanceTest
    {
        private Stopwatch _sw = new Stopwatch();

        public TreeBasePerformanceTest(string name)
        {
            Name = name;
        }

        public string Name { get; private set; }

        public void CheckRandomContains(int randomSeed, int singleItemChecks)
        {
            Random rnd = new Random(randomSeed);
            _sw.Restart();
            for (int i = 0; i < singleItemChecks; i++)
            {
                ImplementedCheckRandomContains(rnd.Next());
            }
            _sw.Stop();
            Console.WriteLine("{0}: {1}", Name, _sw.Elapsed);
        }

        public void FillDataSources(IEnumerable<int> dataSet)
        {
            _sw.Restart();
            CreateNewInstance();
            foreach (var item in dataSet)
            {
                ImplementedAdd(item);
            }
            _sw.Stop();
            Console.WriteLine("{0}: {1}", Name, _sw.Elapsed);
        }

        public void FillDataSources(int fillRandomSeed, int dataCount)
        {
            Random rnd = new Random(fillRandomSeed);
            _sw.Restart();
            CreateNewInstance();
            for (int i = 0; i < dataCount; i++)
            {
                ImplementedAdd(rnd.Next());
            }
            _sw.Stop();
            Console.WriteLine("{0}: {1}", Name, _sw.Elapsed);
        }

        public void RemoveRandomValues(int randomSeed, int singleItemChecks)
        {
            Random rnd = new Random(randomSeed);
            _sw.Restart();
            for (int i = 0; i < singleItemChecks; i++)
            {
                ImplementedRemove(rnd.Next());
            }
            _sw.Stop();
            Console.WriteLine("{0}: {1}", Name, _sw.Elapsed);
        }

        protected abstract void CreateNewInstance();

        protected abstract void ImplementedAdd(int item);

        protected abstract void ImplementedCheckRandomContains(int item);

        protected abstract void ImplementedRemove(int item);
    }
}